home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Communication / Weather / Source / ColorScroller.m < prev    next >
Text File  |  1993-11-12  |  2KB  |  91 lines

  1. /*
  2.  * A scrollbar with pastel Media Lab colors.
  3.  * Look in License.m for example of use.
  4.  * By Michael Hawley, with help from Bruce Blumberg.
  5.  */
  6. /*
  7.     Copyright (c) 1991, 1992 by the MIT Media Laboratory
  8.     
  9.     This software is distributed by Michael Hawley of the MIT Media Laboratory. 
  10.     We hope it will be useful to you.
  11.     
  12.     Permission to use, copy, or modify this software for educational 
  13.     and research purposes only and without fee is hereby granted 
  14.     provided this notice appears on all copies, and provided you send 
  15.     us your improvements.  Any other use of this software, in original 
  16.     or modified form, in whole or in part, requires specific permission 
  17.     from MIT.  This software shall not be used, rewritten, or adapted 
  18.     for use in a commercial product without first obtaining appropriate 
  19.     licenses from MIT.  MIT makes no representations about the suitability 
  20.     of this software for any purpose: it is provided "as is" without any 
  21.     warranty and any risk, damage, or liability incurred through your use 
  22.     of this software is yours alone.
  23.     
  24.     Michael Hawley
  25.     MIT Media Laboratory
  26.     20 Ames Street, 
  27.     Cambridge, MA 02139
  28.     mike@media-lab.mit.edu
  29. */
  30.  
  31. #import <appkit/appkit.h>
  32. #import "ColorScroller.h"
  33.  
  34. #define N 8
  35.  
  36. static float pct[N] = {.0790, .1535, .0564, .2279, .0745, .2596, .1083, .0406};
  37. static NXColor color[N];
  38.  
  39. static void
  40. initColors(){
  41.     int i = 0;
  42. #define mix(a,b) (a-p*(a-b))
  43. #define M(x) (170.0-0.3*(170-x))/256.0
  44. #define C(r,g,b) color[i++] = NXConvertRGBToColor(M(r), M(g), M(b));
  45.     C(77.0,17.0,93.0)
  46.     C(0.0,85.0,0.0)
  47.     C(255.0,255.0,255.0)
  48.     C(210.0,0.0,0.0)
  49.     C(255.0,90.0,0.0)
  50.     C(0.0,0.0,151.0)
  51.     C(255.0,248.0,0.0)
  52.     C(85.0,85.0,85.0)
  53. }
  54.  
  55. @implementation ColorScroller
  56.  
  57. -initFrame:(const NXRect *)r {
  58.     [super initFrame:r];
  59.     [self setEnabled:YES];
  60.     [self setArrowsPosition:NX_SCROLLARROWSNONE];
  61.     initColors();
  62.     return self;
  63. }
  64.  
  65. - drawBackground {
  66.     NXRect r;
  67.     int i;
  68.     float h;
  69.     
  70.     [self calcRect:&r forPart:NX_KNOBSLOT];
  71.     r.origin.x += 1; r.size.width -= 2;
  72.     r.origin.y += 1; r.size.height -= 2;
  73.     h = r.size.height;
  74.     /* now r is the size that you can draw into */
  75.     for(i=0;i<N;i++){
  76.     r.size.height = h * pct[i];
  77.     NXSetColor(color[i]);
  78.     NXRectFill(&r);
  79.     r.origin.y += r.size.height;
  80.     }
  81.     return self;
  82. }
  83.  
  84. - drawKnob {
  85.     [self drawBackground];
  86.     [super drawKnob];
  87.     return self;
  88. }
  89.  
  90. @end
  91.